document.querySelector('[type="button"]').onclick=function(){
    var username =document.querySelector('[type="text"]').value
    var password =document.querySelector('[type="password"]').value
    if(username===''){
        layer.msg('用户名不能为空')
        return false;
    }
    if(password===''){
        layer.msg('密码不能为空')
        return false;
    }
    var index = layer.load(1, {
        shade: [0.8,'#fff'] //0.1透明度的白色背景
      });

   sendAjax({
       url:'./php/login.php',
       method:'post',
       data:{
        username,
        password
       },
       success:res=>{
           var {meta:{status,msg}}=res;
           layer.close(index)

           if(status===1){
            layer.msg(msg,{
                icon: 1,
                time:1000
            },()=>{
                sCookie('username',username,7200)
                let url =localStorage.getItem('url')
                if(url){
                    localStorage.removeItem("url")
                    location.href=url
                }else{
                    location.href='./home.html'
                }
              
            })
              
           }else{
            layer.msg(msg,{
                icon:2,
                time:1000
            })
           }

          
       }
   })
}
